package d_用户信息.a_用户信息.c_支付胡获取Unionid;

import a_接口调用凭证.a_获取接口调用凭据.GetAccessToken;
import c_小程序登录.a_小程序登录.Code2Session;
import my.wechat.rc.common.HttpClientUtil;
import my.wechat.rc.common.MapUtil;

/**
 * @author 86153
 * @date 2022/8/3
 **/
public class GetPaidUnionid {

    public static GetPaidUnionidResponse getPaidUnionid() {
        try {
            //未测试
            Code2Session.Code2SessionResponse code2SessionResponse = Code2Session.code2Session("043ZiFFa1iXaED0cDlGa1I9wZm3ZiFFU");
            String accessToken = GetAccessToken.getAccessToken().getAccessToken();
            String url = "https://api.weixin.qq.com/wxa/getpaidunionid?access_token=" + accessToken;
            return HttpClientUtil.get(url, MapUtil.of("openid", code2SessionResponse.getOpenid(),
                    "transaction_id",null,
                    "mch_id",null,
                    "out_trade_no", null),
                    GetPaidUnionidResponse.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new GetPaidUnionidResponse();
    }

    public static void main(String[] args) {
        getPaidUnionid();
    }

    public static class GetPaidUnionidResponse {
        private String unionid;
        private Integer errcode;
        private String errmsg;

        public String getUnionid() {
            return unionid;
        }

        public void setUnionid(String unionid) {
            this.unionid = unionid;
        }

        public Integer getErrcode() {
            return errcode;
        }

        public void setErrcode(Integer errcode) {
            this.errcode = errcode;
        }

        public String getErrmsg() {
            return errmsg;
        }

        public void setErrmsg(String errmsg) {
            this.errmsg = errmsg;
        }
    }
}
